package com.aviation.sell_ticket.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.CustomExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;

/**
 * 延迟交换机
 */
@Configuration
public class RabbitMQConfig {

    public static final String ORDER_EXCHANGE = "order.exchange";

    public static final String ORDER_QUEUE = "order.queue";

    public static final String ORDER_ROUTING_KEY = "order.routingkey";


    @Bean
    public CustomExchange delayedExchange(){
        HashMap<String,Object> arguments = new HashMap<>();
        arguments.put("x-delayed-type","direct");
        return new CustomExchange(ORDER_EXCHANGE,"x-delayed-message",
                true,false,arguments);
    }

    @Bean
    public Queue queueDe(){
        return new Queue(ORDER_QUEUE,true);
    }

    @Bean
    public Binding queueBindingExchange(
            @Qualifier("queueDe") Queue queue,
            @Qualifier("delayedExchange") CustomExchange customExchange){
        return BindingBuilder.bind(queue).to(customExchange).with(ORDER_ROUTING_KEY).noargs();
    }
}

